//Title  : Useful Javascript functions
//Desp   :
//Author : 蔡源
//Date   : 2006-9-28

function isEmpty(str)
{
	return ((str == null) || (str.length == 0));
}

function isNull(str)
{
	var flag = false;
	for (i = 0; i < str.length; i++)
	{
		if (str.charAt(i) != ' ')
			flag = true;
	}
	return !flag;
}

function haveChinese(str)
{		
	for (i = 0; i < str.length; i++)
		if (str.charCodeAt(i) > 127)
			return true;
	return false;
}

function isChinese(str)
{
	var flag = false;
	for (i = 0; i < str.length; i++)
	{
		flag = str.charCodeAt(i)>127
		if (!flag)	return flag;
	}
	return flag;
}

function isLetter(str)
{
	for (i = 0; i < str.length; i++)
	{
		if((str.charCodeAt(i)>=65&&str.charCodeAt(i)<=90)||(str.charCodeAt(i)>=97&&str.charCodeAt(i)<=122))
		return true;
	}
	return false;
}

function ansiLength(str)
{
	var len = 0;
	for (i = 0; i < str.length; i++)
	{
		if (str.charCodeAt(i) > 127)
			len = len + 2;
		else
			len++;
	}
	return len;	
}

function sl_alert(errinfo, url)
{
	alert("系统提示：　　　　\n\n" + errinfo + "\n\n");
	if (url != null)
		location.replace(url);
}

function sl_confirm(confirm_info)
{
	return confirm("系统确认：\n\n您确认要" + confirm_info + "吗？");
}

function sl_continue(confirm_info)
{
	return confirm("系统确认：\n\n" + confirm_info + "，您确认要继续吗？");
}

function sl_check(field, name, maxlength, minlength)
{	
	var str;
	str =field.value;
	str=str.replace(/^\s+|\s+$/g, "");
	if(minlength != 0 && str == "")
	{
		sl_alert("'"+name + "'不能为空或以空格开头，请您填写'" + name + "'！");
		field.focus();
		field.select();
		return false;
	}

	if(minlength != 0 && ansiLength(field.value) < minlength)
	{
		if(minlength == maxlength)
			sl_alert("'"+name + "'的长度必须是" + minlength + "位，请您重新填写！");
		else
			sl_alert("'"+name + "'的长度至少需要" + minlength + "位以上，请您重新填写！");
		field.focus();
		return false;
	}
	if(maxlength != 0 && ansiLength(field.value) > maxlength)
	{
		sl_alert("'"+name + "'的长度不能超过" + maxlength + "个字符，请您重新填写！");
		field.focus();
		return false;
	}
	return true;
}

function sl_checkInt(field, name, maxValue,minValue)
{
    var i, str
    if (!sl_check(field, name, 0, 0))
        return false;
    str = field.value;
    for (i = 0; i < str.length; i++)
    {
        if (str.charAt(i) != ',')
        {
            if (str.charCodeAt(i) < 48 || str.charCodeAt(i) > 57)
            {
                sl_alert("'"+ name + "'必须是整数数字，请您重新填写！");
                field.focus();
                field.select();
                return false;
            }
        }
    }
    var strInt = parseInt(str);    
    if(strInt<minValue||strInt>maxValue)
    {
        sl_alert("'"+name + "'的值必须在 " + minValue + " 到 " + maxValue + " 之间，请您重新填写！");
        field.focus();
        field.select();
       return false;
    }
    return true;
}

/**
 * 20050809：由于可以包含负号，所以整数长度的检验要增加判断
 */
function sl_checkDecimal(field, name, intlen, pointlen, minlength)
{
	var pos1, pos2, ilen, plen;
	if(!sl_checkFloat(field, name, 1000, minlength))
		return false;
	if ((minlength == 0) && (field.value.length == 0))
		return true;
	pos1 = field.value.indexOf(".");
	pos2 = field.value.lastIndexOf(".");
	if ((pos1 >= 0) && ((pos2 > pos1) || (field.value.length < 3)))
	{
		sl_alert("数字格式无效，请您输入有效的'"+ name +"'！");
		field.focus();
		field.select();
		return false;
	}
	if ((pos1 == 0) || (pos1 == field.value.length - 1))
	{
		sl_alert("数字格式无效，请您输入有效的'"+ name +"'！");
		field.focus();
		field.select();
		return false;
	}
	if (pos1 == -1)
	{
		ilen = field.value.length;
		plen = 0;
	}
	else
	{
		ilen = pos1;
		plen = field.value.length - pos1 - 1;
	}
	if(field.value.indexOf("-")==0)
	{
		ilen--;
	}
	if(ilen > intlen)
	{
		sl_alert("数字格式无效，整数位数不能超过" + intlen + "位，请您输入有效的'"+ name +"'！");
		field.focus();
		field.select();
		return false;
	}
	if (plen > pointlen)
	{
		sl_alert("数字格式无效，小数位数不能超过" + pointlen + "位，请您输入有效的'"+ name +"'！");
		field.focus();
		field.select();
		return false;
	}
	return true;
}

/**
 *	比较两个浮点数的大小
 */
function sl_compareDecimal(field1,name1,field2,name2)
{
	if(!sl_checkDecimal(field1, name1, 999, 999, 0))
		return false;
	if(!sl_checkDecimal(field2, name2, 999, 999, 0))
		return false;
	if(parseFloat(field1.value)>parseFloat(field2.value))
	{
		sl_alert(name1+"不能大于"+name2+"！");
		return false;
	}
	return true;	
}

function sl_checkChoice(field, name)
{
	if (field.value == null || field.value == "")
	{
		sl_alert("请选择'" + name + "'！");
		field.focus();
		return false;
	}
	return true;
}


function sl_checkFloat(field, name, maxlength, minlength)
{
	var i, j, str;
	if (!sl_check(field, name, maxlength, minlength))
		return false;
	str = field.value;
	j = 0;
	if (str != "" && str.charAt(0) == '-')
		j = 1;
	for (i = j; i < str.length; i++)
	{
		if (str.charAt(i) != '.')
		{
			if (str.charCodeAt(i) < 48 || str.charCodeAt(i) > 57)
			{
				sl_alert("'"+name + "'必须是数字，请您重新填写！");
				field.focus();
				field.select();
				return false;
			}
		}
	}
	return true;
}

function sl_checkBox(field,name)
{	
	if(field == null)
	{
		sl_alert("无可选项！");	
		return false;
	}

	if(field.length == null)
	{
		
		if(field.checked)
			return true;
		else
		{
			sl_alert("请选择'" + name + "'！");	
			return false;
		}
	}
	
		
	for(i=0;i<field.length;i++) 
	{
		if(field[i].checked)
		{
			return true;
		}	
	}
	sl_alert("请选择'" + name + "'！");	
	return false;
}

function sl_parseFloat(value)
{
	var s = "";
	for (var i = 0; i < value.length; i++)
	{
		if (value.charAt(i) != ',')
			s = s + value.charAt(i)
	}
	if (s == "")
		return 0
	else
		return parseFloat(s);
}

function popWindow(url)
{
	return window.open(url,"","resizable=0,scrollbars=yes,status=no,toolbar=no,location=no,menu=no,width=600,height=500,left=0,top=0")
}

function isCharsInBag(s, bag)
{
	var i;
	// Search through string's characters one by one.
	// If character is in bag, append to returnString.
	for (i = 0; i < s.length; i++)
	{
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) return false;
	}
	return true;
}

function isEmail(s, name)
{
	if (s.value.length > 0 && !s.value.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) ) {
		sl_alert("Email格式错误，请重新输入！");
		s.focus();
		s.select();
		return false;
	}
	return true;
}

function openWin(url, name, w, h)
{
	var left=0;
	var top=0;
	left=(screen.width-w)/2;
	top=(screen.height-h)/2;	
	return window.open(url,name,"width=" + w + ",height=" + h + ",left="+left+",top="+top+",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no")
}

function chachEsc(nKeyCode)
{
	if (27 == nKeyCode)
	{		
		window.close();
	}
}


function invertVisible(element)
{
	if(element.style.display == "")
		element.style.display = "none";
	else
		element.style.display = "";
}

function checkedCount(element)
{
	var iCount = 0;
	var i;
	
	if(element == null)
		return 0;
		
	if(element.length == null)
	{
		if(element.checked)
			return 1;
		else
			return 0;
	}

	for(i = 0; i < element.length; i++)
		if(element[i].checked)
			iCount++;

	return iCount;
}

function getCheckBoxValues(element)
{
	var ret = "";
	if(element == null)
		return "";

	if(element.length == null)
	{
		
		if(element.checked)
			return element.value;
		else
			return "";
	}

	for(i = 0; i < element.length; i++)
		if(element[i].checked)
			ret=ret+element[i].value+",";
	var point = ret.lastIndexOf(",");		
	if(point>0)
		ret = ret.substring(0,point);

	return ret;
}

function nextKeyPress(ce, forceNext)
{
	if (event.keyCode == 13 || forceNext)
	{
		event.keyCode = 9;
		return true;
	}
}

function getMatch(srcStr,mark,vaction)
{
	var i;

	i=srcStr.indexOf(mark);
	if (i>0){
		if (vaction==0)
			return (srcStr.substring(0,i));
		else
			return (srcStr.substring(i+1));
	} else
		return srcStr;
}

function isNum(s, prompt,flag)
{
	var i;
	var str;
	str = s.value;
	if(flag)
	{
		if (str == null||str.length <= 0)
		{
			sl_alert("'"+prompt+"'不能为空！");
			s.focus();
			s.select();
			return false;
		}	
	}	
	for (i = 0; i < str.length; i++)
	{
		if (str.charCodeAt(i) < 48 || str.charCodeAt(i) > 57)
		{
			sl_alert("'"+prompt+"'只能是数字！");
			s.focus();
			s.select();
			return false;
		}
	}
	return true;
}


function isFloat(s, prompt)
{
	var i;
	var str;
	str=s.value;
	if (str == null)
		return false;
	if (str.length <= 0)
		return false;
	for (i = 0; i < str.length; i++)
	{
		if (str.charAt(i) != "." && str.charAt(i) != "-")
		{
			if (str.charCodeAt(i) < 48 || str.charCodeAt(i) > 57)
			{
				sl_alert(prompt);
				s.focus();
				s.select();
				return false;
			}
		}
	}
	return true;
}

//2005-12-23  16进制转换10进制
function convert16To10(s)
{
	if(s == null||s =="")
	{		
		return "";
	}	
	else
		return parseInt("0x"+s,16);
}
//10进制转换16进制
function convert10To16(s)
{
	if(s == null||s =="")
		return "";
	else	
		return parseInt(s).toString(16);
}

function selectAllBox(checkname)
{
	
	if(checkname == null)
		return;
	var iCount = checkedCount(checkname);
	var i;

	if(checkname.length == null)
	{
		checkname.checked = iCount < 1;
		return;
	}

	for(i = 0; i < checkname.length; i++)
		checkname[i].checked = iCount < checkname.length;
}

function trimNullElement(element)
{
	if (element.value = "null")
		element.value = "";
}

function confirmExit()
{
	var r = sl_confirm("退出系统");
	if(r)
		top.location = "/exit.jsp";	
}

function confirmReLoad()
{
	var r = sl_confirm("重新登录");
	if(r)
		top.location = "/reload.jsp";	
}


function sl_remove_ok(url)
{
	alert("系统提示：　　　　\n\n删除成功！\n\n");  // in default.vbs
	if (url != null)
		location.replace(url);
}

function sl_logout_ok(url)
{
	alert("系统提示：　　　　\n\n注销成功！\n\n");  // in default.vbs
	if (url != null)
		location.replace(url);
}

function sl_update_ok(url)
{
	alert("系统提示：　　　　\n\n保存成功！\n\n");  // in default.vbs
	if (url != null)
		location.replace(url);
}

function sl_confirmUpdate(doNew)
{
	if (doNew == "null")
		return sl_confirm("保存");
	else
		return sl_confirm("保存修改");
}

function sl_checkIp(field,name)
{
	 var check= function(v){try{return (v<=255 && v>=0)}catch(x){return false}};
	 var re=field.value.split(".");
	 var ret = (re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false
	 if(ret)
	 	return true;
	 else
	 {	 	
	 	sl_alert("请选择" + name + "！");	
	 	field.focus();
        field.select();
	 	return false;
	 }
}

function confirmResumeOne(element)
{
	if (element == null)
	{
		sl_alert("未选定任何记录！");
		return false;
	}
	return sl_confirm('恢复选定的记录');
}


function confirmRemoveOne(element)
{
	if (element == null)
	{
		sl_alert("未选定任何记录！");
		return false;
	}
	return sl_confirm('删除选定的记录');
}


function confirmRemove(element)
{
	if (element == null)
	{
		sl_alert("未选定任何记录！");
		return false;
	}
	if(checkedCount(element) == 0)
	{
		sl_alert("请选定要删除的记录！");
		return false;
	}
	return sl_confirm('删除选定的记录');
}

function confirmCreate(element)
{
	if (element == null)
	{
		sl_alert("未选定任何记录！");
		return false;
	}
	if(checkedCount(element) == 0)
	{
		sl_alert("请选定要生成的记录！");
		return false;
	}
	return sl_confirm('生成选定的记录');
}

function confirmResume(element)
{
	if (element == null)
	{
		sl_alert("未选定任何记录！");
		return false;
	}
	if(checkedCount(element) == 0)
	{
		sl_alert("请选定要恢复的记录！");
		return false;
	}
	return sl_confirm('恢复选定的记录');
}

function confirmCancel(element)
{
	if (element == null)
	{
		sl_alert("未选定任何记录！");
		return false;
	}
	if(checkedCount(element) == 0)
	{
		sl_alert("请选定要注销的记录！");
		return false;
	}
	return sl_confirm('注销选定的记录');
}

function confirmSave(element)
{
	if (element == null)
	{
		sl_alert("未选定任何记录！");
		return false;
	}
	if(checkedCount(element) == 0)
	{
		sl_alert("请选定要保存的记录！");
		return false;
	}
	return sl_confirm('保存选定的记录');
}

function isBetween(element,low,high,point,caption)
{
	var s;
	if (element == null) 
		return false;
	var str=element.value;
	s=element.value;
	if (str==null)	
		return false;
	if (str.length<1)
		return false;
	var str=element.value;	
	if (s<low || s>=high)
	{
		alert(caption);
		element.focus();
		element.select();
		return false;	
	}
	var i=0;
		
	i=str.indexOf(".");
	if (i>0)
	{
		var len=str.length;
		if (len-i-1>point)
		{
			alert("小数点后最多有"+point+"位!");
			element.focus();
			element.select();
			return false;
		}	
	}
	return true;	
}


function findElement(name)
{
	return document.all(name);
}

function enableElements(element, enable)
{
	var i;
	for (i = 0; i < element.all.length; i++)
		element.all.item(i).disabled = !enable;
}

function cTrim(sInputString,iType)
{ 
    var sTmpStr = ' ';
    var i = -1;

    if(iType == 0 || iType == 1)
    {
        while(sTmpStr == ' ')
        {
            ++i;
            sTmpStr = sInputString.substr(i,1);
        }
        sInputString = sInputString.substring(i);
    }
    if(iType == 0 || iType == 2)
    {
        sTmpStr = ' ';
        i = sInputString.length;
        while(sTmpStr == ' ')
        {
            --i;
            sTmpStr = sInputString.substr(i,1);
        }
        sInputString = sInputString.substring(0,i+1);
    }
    return sInputString;
} 

function trim(s)
{
	return s.replace(/(^\s*)|(\s*$)/g, "");	
}

function trimZero(s)
{
	var result = s, s1;
	var n1 = 0, n2 = 0;
	s1 = s;
	
	n1 = s1.indexOf("零仟零佰零拾零万");
	while (n1 > 0)
	{
		result = s1.substring(0, n1) + s1.substring(n1 + 8);
		s1 = result;		
		n1 = s1.indexOf("零仟零佰零拾零万");
	}	
	n1 = s1.indexOf("零拾");
	
	while (n1 > 0)
	{
		result = s1.substring(0, n1) + s1.substring(n1 + 2);
		s1 = result;
		n1 = s1.indexOf("零拾");
	}
	n1 = s1.indexOf("零佰");
	while (n1 > 0)
	{
		result = s1.substring(0, n1) + s1.substring(n1 + 2);
		s1 = result;
		n1 = s1.indexOf("零佰");
	}
	n1 = s1.indexOf("零仟");
	while (n1 > 0)
	{
		result = s1.substring(0, n1) + s1.substring(n1 + 2);
		s1 = result;
		n1 = s1.indexOf("零仟");
	}
	n1 = s1.indexOf("零元");
	while (n1 > 0)
	{
		result = s1.substring(0, n1) + s1.substring(n1 + 1);
		s1 = result;
		n1 = s1.indexOf("零元");
	}
	n1 = s1.indexOf("零角");
	while (n1 > 0)
	{
		result = s1.substring(0, n1) + s1.substring(n1 + 2);
		s1 = result;
		n1 = s1.indexOf("零角");
	}
	n1 = s1.indexOf("零分");
	while (n1 > 0)
	{
		result = s1.substring(0, n1) + s1.substring(n1 + 2);
		s1 = result;
		n1 = s1.indexOf("零分");
	}
	n1 = s1.indexOf("零万");
	while (n1 > 0)
	{
		if (s1.substring(0, n1).length > 0)
		    result = s1.substring(0, n1) + s1.substring(n1 + 1);
		else
			result = s1.substring(0, n1) + s1.substring(n1 + 2);
		s1 = result;
		n1 = s1.indexOf("零万");
	}	
	n1 = s1.indexOf("零亿");
	while (n1 > 0)
	{
		if (s1.substring(0, n1).length > 0)
			result = s1.substring(0, n1) + s1.substring(n1 + 1);
		else
			result = s1.substring(0, n1) + s1.substring(n1 + 2);
		s1 = result;
		n1 = s1.indexOf("零亿");
	}
	return result;
}


function numToChinese1(input)
{
	var s1 = "零壹贰叁肆伍陆柒捌玖";
	var s4 = "分角整元拾佰仟万拾佰仟亿拾佰仟";
	var temp = "";
	var result = "";
	var bZero = false;

	if (input == null)
		return "输入字串不是数字串只能包括以下字符（'0'～'9'，'.')，输入字串最大只能精确到仟亿，小数点只能两位！";
	
	
	var temp = trim(input);

	var f = parseFloat("0" + temp);
	var len = 0;
	if (temp.indexOf(".") == -1)
		len = temp.length;
	else
		len = temp.indexOf(".");
	if (len > s4.length - 3)
		return "输入字串最大只能精确到仟亿，小数点只能两位！";

	var n1, n2 = 0;
	var num = "";
	var unit = "";

	for (var i = 0; i < temp.length; i++)
	{
		if (i > len + 2)
		{
			break;
		}
		if (i == len)
		{
			continue;
		}
		n1 = parseInt(temp.charAt(i));
		num = s1.substring(n1, n1 + 1);
		n2 = len - i + 2;
		unit = s4.substring(n2, n2 + 1);
		result = result + num + unit;
	}
	if ((len == temp.length) || (len == temp.length - 1))
		result = result + "整";
	if (len == temp.length - 2)
		result = result + "零分";
		
	result = trimZero(result);
	return result;
}

 // 数字金额转换汉字金额
 function numToChinese(numberValue){
  
  var numberValue=new String(Math.round(numberValue*100)); // 数字金额
  var chineseValue="";          // 转换后的汉字金额
  var String1 = "零壹贰叁肆伍陆柒捌玖";       // 汉字数字
  var String2 = "万仟佰拾亿仟佰拾万仟佰拾元角分";     // 对应单位
  var len=numberValue.length;         // numberValue 的字符串长度
  var Ch1;             // 数字的汉语读法
  var Ch2;             // 数字位的汉字读法
  var nZero=0;            // 用来计算连续的零值的个数
  var String3;            // 指定位置的数值
  
  if (numberValue==0){
   
   chineseValue = "零元整";
   return chineseValue;
   
  }
  
  String2 = String2.substr(String2.length-len, len);   // 取出对应位数的STRING2的值
  
  for(var i=0; i<len; i++){
   
   String3 = parseInt(numberValue.substr(i, 1),10);   // 取出需转换的某一位的值
   //alert(String3);
   if ( i != (len - 3) && i != (len - 7) && i != (len - 11) && i !=(len - 15) ){
    
    if ( String3 == 0 ){
     
     Ch1 = "";
     Ch2 = "";
     nZero = nZero + 1;
     
    }else if ( String3 != 0 && nZero != 0 ){
     
     Ch1 = "零" + String1.substr(String3, 1);
     Ch2 = String2.substr(i, 1);
     nZero = 0;
     
    }else{
     
     Ch1 = String1.substr(String3, 1);
     Ch2 = String2.substr(i, 1);
     nZero = 0;
    }
   }else{              // 该位是万亿，亿，万，元位等关键位
    if( String3 != 0 && nZero != 0 ){
     
     Ch1 = "零" + String1.substr(String3, 1);
     Ch2 = String2.substr(i, 1);
     nZero = 0;
     
    }else if ( String3 != 0 && nZero == 0 ){
     
     Ch1 = String1.substr(String3, 1);
     Ch2 = String2.substr(i, 1);
     nZero = 0;
     
    }else if( String3 == 0 && nZero >= 3 ){
     
     Ch1 = "";
     Ch2 = "";
     nZero = nZero + 1;
     
    }else{
     
     Ch1 = "";
     Ch2 = String2.substr(i, 1);
     nZero = nZero + 1;
     
    }
    
    if( i == (len - 11) || i == (len - 3)) {    // 如果该位是亿位或元位，则必须写上
     Ch2 = String2.substr(i, 1);
    }
    
   }
   chineseValue = chineseValue + Ch1 + Ch2;
   
  } 
  
  if ( String3 == 0 ){           // 最后一位（分）为0时，加上“整”
   chineseValue = chineseValue + "整";
  }
  
  return chineseValue;
 } 
//*****************判断日期*********************************
//20041118 Created by CaiYuan
//判断日期格式的步骤:  1.判断是否有非法字符，日期中只能包含数字和分隔符
//					  2.判断日期中是否有两个分隔符把字符串分成3份，即年、月、日
//					  3.判断日期年、月、日是否合法
//					  4.在月的基础上判断日的合法性(是否闰年)
function sl_checkDate(DateString,DateName)
{	
	var info = "日期格式不合法 ";
	
	var separator = '-';  	//分隔符必须是‘-’
	var tempy = ''; 		//年
	var tempm = ''; 		//月	
	var tempd = ''; 		//日
	var tempArray; 
//1。。。。			
	if (!isCharsInBag( DateString.value, "0123456789-"))
	{
		sl_alert(DateName + "中只能包含0123456789和分隔符'-'\n" + "请您重新输入"+ DateName);
		DateString.focus();
		DateString.select();
		return false;
	}
	if (!sl_check(DateString, DateName, 10, 8))
	{
		DateString.focus();
		DateString.select();
		return false; 
	}		
//2。。。。
	tempArray = DateString.value.split(separator); 	
	
	if (tempArray.length!=3) 	//判断是否被分隔成3份（年、月、日）
	{	
		sl_alert(info +",请重新输入!");
		DateString.focus();
		DateString.select();
		return false; 
	}
//3。。。。
	//判断年的合法性
	if (tempArray[0].length!=4) 
	{
		sl_alert(info + ",请输入有效的年份!");
		DateString.focus();
		DateString.select();
		return false;
	}
	else
	{
		tempy = tempArray[0];
	}
	//判断月的合法性	
	if (tempArray[1].length!=2) 
	{
		sl_alert(info + ",请输入有效的月份!");
		DateString.focus();
		DateString.select();
		return false;
	}
	else
	{
		tempm = tempArray[1];
		if(tempm<1||tempm>12) 
		{ 
   			sl_alert("月份必须在01和12之间!"); 
    		DateString.focus();
			DateString.select();
    		return false; 
    	}		
	}
	//判断日的合法性	
	if (tempArray[2].length!=2) 
	{
		sl_alert(info + ",请输入有效的日期!");
		DateString.focus();
		DateString.select();
		return false;		
	}
	else
	{
		tempd = tempArray[2];
		if(tempd<1||tempd>31)
		{ 
   			 sl_alert("日期必须在01和31之间!");
   			 DateString.focus();
			 DateString.select(); 
   		 	 return false; 
 		}
 		else
 		{   
 			if(tempm == 2)
 			{  
     			if(isLeapYear(tempy)&&tempd>29)
     			{ 
       				alert("该年为闰年，二月份日期必须在01到29之间!"); 
      				DateString.focus();
					DateString.select(); 
       				return false; 
     			}       
 				if(!isLeapYear(tempy)&&tempd>28)
 				{ 
      			     alert("该年不是闰年，二月份日期必须在01到28之间!");
       			     DateString.focus();
					 DateString.select(); 
      				 return false; 
     			} 					    			
 			}
			if((tempm == 4||tempm == 6||tempm == 9||tempm == 11)&&tempd>30) 
			{
				alert("该月没有31号" + ",请输入有效的日期!"); 
      				DateString.focus();
					DateString.select(); 
       				return false; 
			}	
 		}
	}		
	return true;
}

//闰年判断
function isLeapYear(year) 
{ 
 	if((year%4==0&&year%100!=0)||(year%400==0)) 
 	{ 
 		return true; 
 	} 	 
 		return false; 
} 
//*********************************************************
//计算输入字符串的长度
function showLength(input) 
{
	var temp = trim(input);		
	var tempArray = temp.split(' ');
	var result = "";	
	for(var i=0;i<tempArray.length;i++)
	{	
		result = result + tempArray[i];		
	}	
	return result.length;
}
//根据输入金额显示相应的中文名
function showCnMoney(value,name)
{	
	if (trim(value) == "")
		name.innerText = "";
	else
		name.innerText = "(" + numToChinese(value) + ")";
}
//*****************判断日期---无分隔符*********************************
//20041230 Created by CaiYuan
//判断日期格式的步骤:  1.判断是否有非法字符，日期中只能包含数字，且只能是8位
//					  2.substring把日期分割成年、月、日
//					  3.判断日期年、月、日是否合法
//					  4.在月的基础上判断日的合法性(是否闰年)
function sl_checkNumDate(DateString,DateName)
{	
	var info = "日期格式不合法 ";
	
	var tempy = ''; 		//年
	var tempm = ''; 		//月	
	var tempd = ''; 		//日	
//1。。。。			
	if (!isCharsInBag( DateString.value, "0123456789"))
	{
		sl_alert(DateName + "中只能包含0123456789\n" + "请您重新输入"+ DateName);
		DateString.focus();
		DateString.select();
		return false;
	}
	if (!sl_check(DateString, DateName, 8, 8))
	{
		DateString.focus();
		DateString.select();
		return false; 
	}		
//2。。。。
	tempy = DateString.substring(0,3); 	
	tempm = DateString.substring(4,5); 
	tempd = DateString.substring(6,7); 
//3。。。。
	//判断年的合法性
	if (tempy<1800||tempy>3000) 
	{
		sl_alert(info + ",请输入有效的年份!");
		DateString.focus();
		DateString.select();
		return false;
	}	
	//判断月的合法性	
	if(tempm<1||tempm>12) 
	{ 
   		sl_alert("月份必须在01和12之间!"); 
    		DateString.focus();
		DateString.select();
    		return false; 
    	}
	//判断日的合法性	
	if(tempd<1||tempd>31)
	{ 
		 sl_alert("日期必须在01和31之间!");
 		 DateString.focus();
		 DateString.select(); 
 	 	 return false; 
 	}
 	else
 	{   
 		if(tempm == 2)
 		{  
  			if(isLeapYear(tempy)&&tempd>29)
    			{ 
       				alert("该年为闰年，二月份日期必须在01到29之间!"); 
      				DateString.focus();
					DateString.select(); 
       				return false; 
     			}       
 				if(!isLeapYear(tempy)&&tempd>28)
 				{ 
      			     alert("该年不是闰年，二月份日期必须在01到28之间!");
       			     DateString.focus();
					 DateString.select(); 
      				 return false; 
     			} 					    			
 		}
		if((tempm == 4||tempm == 6||tempm == 9||tempm == 11)&&tempd>30) 
		{
				alert("该月没有31号" + ",请输入有效的日期!"); 
      				DateString.focus();
				DateString.select(); 
       				return false; 
		}	
 	}
return true;
} 

//*********************************************************
//20050127 程序合并更新
function findCount(element,value)
{
	icount=0;
	for(i = 0; i <element.options.length; i++)
	{
		if(element.options[i].value==value)
		{
			icount=1;
			break;
		}	
	}
	return icount;
}


function confirmPrint(element)
{
	if (element == null)
	{
		sl_alert("未选定任何记录！");
		return false;
	}
	if(checkedCount(element) == 0)
	{
		sl_alert("请选定要打印的记录！");
		return false;
	}
	return sl_confirm('打印选定的记录');
}


//计算两个日期相差天数
function getBetweenDays(dateFrom, dateTo)
{
	var objdateFrom = dateFrom;
	var objdateTo = dateTo;
	var sdate = new Date(objdateFrom.value.replace(/-/g,"\/"));
	var edate = new Date(dateTo.value.replace(/-/g,"\/"));
	var n = (edate.getTime()-sdate.getTime())/(24*60*60*1000);
	return n;
}

/**
*获得单选框组中选中的值
*2006-10-10 caiyuan
*/
function getRadioValue(fieldName)
{
	var field = document.getElementsByName(fieldName);
	
	for(i=0;i<field.length;i++) 
	{
		if(field[i].checked)
		{			
			return field[i].value;
		}	
	}	
	return null;
}

/**
* TRUE/FALSE的转换
*/
function switchBoolean(flag)
{
	if(flag)
		return false;
	else
		return true;	
}


/**
*补充的JS数据类型转换
*2006-10-10 caiyuan
*/
function parseBoolean(value)
{
	if(value==null)
		return null;
	else if(value=="true"||value=="1")
		return true;
	else if(value=="false"||value=="0")	
		return false;	
}

/**
*增强型文本区域
*/
function textAreaEx(fieldName, num_r){ 
	document.write("<span onclick=\"javascript:document.getElementById('"+fieldName+ "').rows+= " + num_r + ";\" title=\"拉长\" style=\"cursor:hand\">");
	document.write("<img src=\"../images/down.gif\" border=\"0\"></span>");
	document.write("&nbsp;&nbsp;<span onclick=\"javascript:if(document.getElementById('"+fieldName+ "').rows != "+ num_r + "){document.getElementById('"+fieldName+ "').rows-="+ num_r +";}else{document.getElementById('"+fieldName+ "').rows="+ num_r +";}\" title=\"缩短\" style=\"cursor:hand\">");
	document.write("<img src=\"../images/up.gif\" border=\"0\"></span>");
}

/**
*封装了对BUFFALO回调函数返回结果的处理 - 适用于弹出框
*/
function ajaxDialogReturn(ret)
{ 	
	window.returnValue = true;
	window.close();		
}

/**
*封装了对BUFFALO回调函数返回结果的处理 - 适用于弹出框
*/
function ajaxLocationReturn(ret,url)
{ 	
    if(ret!=null&&ret!="")
    {
		sl_alert(ret);
	}
	else
	{
		sl_update_ok();
		if(url!=null&&url!="")
			location.href = url;
		else
			history.back();//由于使用AJAX页面未刷新，故可以调用这个方法返回前一页
	}	
}

function ajaxSubmit(ret,info,refreshType)
{ 	
    if(ret!=null&&ret!="")
    {
		sl_alert(ret);
	}
	else
	{
		if(info!=null&&info!="")
			sl_alert(info);
		if(refreshType=="reload")
			location.reload();	
		else if(refreshType=="close")
		{
			window.returnValue = true;	
			window.close();	
		}	
	}	
}

/**
*封装了对BUFFALO回调函数返回结果的处理 - 适用于删除
*/
function ajaxDeleteOk(ret)
{ 	
    if(ret!=null&&ret!="")
    {
		sl_alert(ret);
	}
	else
	{
		sl_remove_ok();
		location.reload();		
	}	
}

/**
*封装了对BUFFALO回调函数返回结果的处理 - 适用于本页面更新
*/
function ajaxUpdateOk(ret)
{ 	
    if(ret!=null&&ret!="")
    {
		sl_alert(ret);
	}
	else
	{
		sl_update_ok();
		location.reload();		
	}	
}
